using System.Collections;
using UnityEngine;

public class Gem : MonoBehaviour
{
	public Rigidbody2D rb;

	public SpriteRenderer sr;

	public Collider2D col;

	private Coroutine co;

	private void OnEnable()
	{
		col.enabled = false;
		sr.sprite = Sprites.instance.gemSpriteList[Random.Range(0, Sprites.instance.gemSpriteList.Length)];
		rb.velocity = new Vector2(Random.Range(-7f, 7f), Random.Range(18f, 25f));
		rb.angularVelocity = ((Random.Range(0, 2) != 0) ? (-1000) : 1000);
		Audio.instance.sfx[25].Play();
		DeActive();
	}

	public void DeActive()
	{
		if (co != null)
		{
			StopCoroutine(co);
		}
		co = StartCoroutine(IE_DeActive());
	}

	private IEnumerator IE_DeActive()
	{
		yield return new WaitForSeconds(1f);
		col.enabled = true;
		yield return new WaitForSeconds(10f);
		base.gameObject.SetActive(false);
	}

	private void OnTriggerEnter2D(Collider2D collision)
	{
		if (collision.CompareTag("Player"))
		{
			GetAGem();
			Audio.instance.sfx[26].Play();
			base.gameObject.SetActive(false);
		}
	}

	private void GetAGem()
	{
		PlayerPrefs.SetInt("playerGem", PlayerPrefs.GetInt("playerGem") + 1);
		GM.instance.TXT_myGemAmount.text = "<sprite=3>X" + PlayerPrefs.GetInt("playerGem");
		GM.instance.AT_ShowMyGemForPlaying.Play("ShowMyGemForPlayingShow", -1, 0f);
	}

	private void OnCollisionEnter2D(Collision2D collision)
	{
		if (collision.gameObject.CompareTag("Floor") && rb.velocity.y > 5f)
		{
			Audio.instance.sfx[25].Play();
		}
	}
}
